package com.yiren.manager.service.impl.test;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiren.core.exception.MyException;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.FavoriteSet;
import com.yiren.entity.YrElderTestAnswerRecord;
import com.yiren.entity.YrElderTestResultRecord;
import com.yiren.manager.form.test.YrElderTestAnswerRecordForm;
import com.yiren.manager.repository.test.YrElderTestAnswerRecordRepository;
import com.yiren.manager.repository.test.YrElderTestResultRecordRepository;
import com.yiren.manager.service.iface.test.YrElderTestAnswerRecordService;

@Service("yrElderTestAnswerRecordService")
public class YrElderTestAnswerRecordServiceImpl extends GenericServiceImpl<YrElderTestAnswerRecord, String> implements YrElderTestAnswerRecordService{

	@Autowired
	private YrElderTestResultRecordRepository elderTestResultRecordRepository;
	
	@Autowired
	public YrElderTestAnswerRecordServiceImpl(YrElderTestAnswerRecordRepository repository) {
		super(repository);
	}

	@Transactional
	public void saveBatch(FavoriteSet favoriteSet) throws MyException {
		List<YrElderTestAnswerRecord> elderTestAnswerRecordForms = favoriteSet.getFavorite("elderTestAnswerRecordList", List.class);
		YrElderTestResultRecord elderTestResultRecord = favoriteSet.getFavorite("testResultRecord", YrElderTestResultRecord.class);
		
		for(YrElderTestAnswerRecord entity : elderTestAnswerRecordForms){
			this.repository.save(entity);
		}
		elderTestResultRecordRepository.save(elderTestResultRecord);
	}

}
